﻿package mortal.component.window
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.interfaces.*;

    public class ActivityBaseWindow extends Window
    {
        protected var _titleName:String;
        protected var _bgName:String;
        protected var _windowBg:ScaleBitmap;
        protected var _bg:GImageBitmap;
        protected var _windowTitle:GImageBitmap;
        protected var _enterBtn:GLoadingButton;
        protected var _flowerA:GImageBitmap;
        protected var _flowerB:GImageBitmap;
        protected var _flowerC:GImageBitmap;
        protected var _flowerD:GImageBitmap;

        public function ActivityBaseWindow(param1:ILayer = null, param2:String = "", param3:String = "")
        {
            this._titleName = param2;
            this._bgName = param3;
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.configEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
            this.addWindowBg();
            this.addBg();
            this.addTitle();
            this.addEnterBtn();
            this.addFlower();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._windowBg)
            {
                this._windowBg.dispose(param1);
                this._windowBg = null;
            }
            if (this._bg)
            {
                this._bg.dispose();
                this._bg = null;
            }
            if (this._windowTitle)
            {
                this._windowTitle.dispose(param1);
                this._windowTitle = null;
            }
            if (this._enterBtn)
            {
                this._enterBtn.dispose(param1);
                this._enterBtn = null;
            }
            if (this._flowerA)
            {
                this._flowerA.dispose(param1);
                this._flowerA = null;
            }
            if (this._flowerB)
            {
                this._flowerB.dispose(param1);
                this._flowerB = null;
            }
            if (this._flowerC)
            {
                this._flowerC.dispose(param1);
                this._flowerC = null;
            }
            if (this._flowerD)
            {
                this._flowerD.dispose(param1);
                this._flowerD = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 20;
                _closeBtn.y = -23;
            }
            return;
        }// end function

        protected function addWindowBg() : void
        {
            this._windowBg = UIFactory.bg(-21, -30, -1, -1, this, ImagesConst.ActivityWindowBg);
            return;
        }// end function

        protected function addBg() : void
        {
            if (this._bgName)
            {
                this._bg = UIFactory.gImageBitmap(this._bgName, 0, 0, this);
            }
            return;
        }// end function

        protected function addTitle() : void
        {
            if (this._titleName)
            {
                this._windowTitle = UIFactory.gImageBitmap(this._titleName, 300, 0, this);
            }
            return;
        }// end function

        protected function addEnterBtn() : void
        {
            this._enterBtn = UIFactory.gLoadingButton(ResFileConst.ActivityEnterBtn, 300, 200, 187, 54, this);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onClickEnterBtn);
            return;
        }// end function

        protected function addFlower() : void
        {
            this._flowerA = UIFactory.gImageBitmap(ImagesConst.ActivityTopLeft, -40, -50, this);
            this._flowerB = UIFactory.gImageBitmap(ImagesConst.ActivityTopRight, 100, -50, this);
            this._flowerC = UIFactory.gImageBitmap(ImagesConst.ActivityBottomLeft, 0, -50, this);
            this._flowerD = UIFactory.gImageBitmap(ImagesConst.ActivityBottomRight, 100, -50, this);
            return;
        }// end function

        protected function onClickEnterBtn(event:MouseEvent) : void
        {
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (this._windowBg)
            {
                this._windowBg.setSize(this.width + 41, this.height + 36);
            }
            if (this._windowTitle)
            {
                this._windowTitle.x = (this.width - 204) / 2;
                this._windowTitle.y = -74;
            }
            if (this._enterBtn)
            {
                this._enterBtn.x = (this.width - 187) / 2;
                this._enterBtn.y = this.height - 23;
            }
            if (this._flowerA)
            {
                this._flowerA.x = -52;
                this._flowerA.y = -51;
            }
            if (this._flowerB)
            {
                this._flowerB.x = this.width - 52;
                this._flowerB.y = -51;
            }
            if (this._flowerC)
            {
                this._flowerC.x = -9;
                this._flowerC.y = this.height - 26;
            }
            if (this._flowerD)
            {
                this._flowerD.x = this.width - 75;
                this._flowerD.y = this.height - 26;
            }
            return;
        }// end function

    }
}
